﻿/*
 * Created by SharpDevelop.
 * User: Administrator
 * Date: 2/17/2011
 * Time: 4:06 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using Microsoft.Synchronization.MetadataStorage;
using Microsoft.Synchronization;
using System.Data;

namespace TomatoSynchronizer.Store
{
	/// <summary>
	/// Description of TomatoMetadataStore.
	/// </summary>
	public class TomatoMetadataStore : MetadataStore
	{
		public TomatoMetadataStore()
		{
		}
		
		public override void BeginTransaction(IsolationLevel isolationLevel)
		{
			if (this.isDisposed)
			{
				throw new ObjectDisposedException(this.ToString());
			}
			
			ValidateIsolationLevel(isolationLevel, "isolationLevel");
			
			this.isTransactionAvailable = true;
		}
		
		private static void ValidateIsolationLevel(IsolationLevel isolationLevel, string parameterName)
		{
			//we only support the Snapshot isolationLevel
			if (isolationLevel != IsolationLevel.Snapshot)
			{
				throw new ArgumentOutOfRangeException(parameterName,"UnsupportedIsolationLevel");
			}
		}
		
		public override void CommitTransaction()
		{
			if (this.isDisposed)
			{
				throw new ObjectDisposedException(this.ToString());
			}
			
			this.isTransactionAvailable = false;
		}
	}
}
